// pages/personalCenter/personalCenter.js
var util = require('../../utils/util.js')
var app = getApp()
var rootUrl = app.globalData.rootDocment
var imgPublicUrl = rootUrl + 'Public/Home/images/'

Page({

  /**
   * 页面的初始数据
   */
  data: {
	  username: '',	//	昵称	
	  userID: app.globalData.userID,	//	用户ID
	  userphone: app.globalData.userPhone,	// 用户手机号
	  loginButton: app.globalData.loginButton,
	  personalHeaderName: app.globalData.personalHeaderName,
	  personalHeaderImg: imgPublicUrl + 'personalHeaderImg.jpg',
	  imageArr: {
		 personalHeaderBg: imgPublicUrl + 'personalHeaderBg.jpg',
		 personalHeaderImg: imgPublicUrl + 'personalHeaderImg.jpg',
		 personalHeaderBgPng: imgPublicUrl + 'personalHeaderBg.png',
		 orderIcon: imgPublicUrl + 'orderIcon.jpg',
		 biIcon: imgPublicUrl + 'biIcon.jpg',
		 MoneyDIcon: imgPublicUrl + 'MoneyDIcon.jpg',
		 MyTeamIcon: imgPublicUrl + 'MyTeamIcon.jpg',
		 couponIcon: imgPublicUrl + 'couponIcon.jpg',
		 scanCodeIcon: imgPublicUrl + 'scanCodeIcon.jpg',
		 addressIcon: imgPublicUrl + 'addressIcon.jpg',
		 safeIcon: imgPublicUrl + 'safeIcon.jpg',
		 personalIcon: imgPublicUrl + 'personalIcon.jpg',
		 liuchengIcon: imgPublicUrl + 'liuchengIcon.jpg'
	 },
	 logingtype:false, //登录状态
  //  djphone:null, //大件电话
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  //查询内存，更新账号登录状态
	  if (app.globalData.userLogType) {
		  var logbtn = wx.getStorageSync('loginButton')
		  var perinfodis = wx.getStorageSync('personalHeaderName')
		  if (logbtn === true) {
			  app.globalData.loginButton = true
			  app.globalData.personalHeaderName = false
		  } else if (logbtn === false) {
			  app.globalData.loginButton = false
			  app.globalData.personalHeaderName = true
		  } else {
			  app.globalData.loginButton = true
			  app.globalData.personalHeaderName = false
		  }
	  }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
	  app.publicchangenavigate()
	  this.getpersonalHeaderImg()

    var sessvalue = wx.getStorageSync('sessionid')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.setData({
			username: app.globalData.nickName,
			userID: app.globalData.userID,
			userphone: app.globalData.userPhone,
			loginButton: app.globalData.loginButton,
			personalHeaderName: app.globalData.personalHeaderName,
			logingtype: app.globalData.userLogType
		})

    //请求获取大件的电话号码
    // util.AJAX('Home/Index/getDJPhone',"", function (res) { //方法体
    //   if (res.data.StatusCode == 100) {
    //     that.setData({ djphone: res.data.Info })
    //   } else {
        
    //   }
    // }, 'POST')
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
	  return app.globalshare();
  },
  //用户头像
  getpersonalHeaderImg: function (res) {
    var userinfo = app.globalData.userInfo
    if (userinfo == null) {
      //使用默认图片
      this.setData({ personalHeaderImg: imgPublicUrl + 'personalHeaderImg.jpg' })
    } else {
      //使用获取到的微信头像
      this.setData({ personalHeaderImg: userinfo.avatarUrl })
    }
  },
  personalLoginTap:function(){
	  app.navigateTologing()  //跳转到登录
  },
  tradingRecordTap:function(){
	app.publicnavigateTologing('/pages/tradingRecord/tradingRecord')
  },
  balanceTap:function(){
	app.publicnavigateTologing('/pages/balance/balance')
  },
  bonusTap:function(){
	app.publicnavigateTologing('/pages/Bonus/Bonus')
  },
  troopsTap:function(){
	app.publicnavigateTologing('/pages/troops/troops')
  },
  addressListTap:function(){
	app.publicnavigateTologing('/pages/address_list/address_list')
  },
  securityTap:function(){
	  if (app.checkLogin()){
		  app.publicnavigateTologing('/pages/securityCenter/securityCenter')
	 	}else{
		  app.navigateTologing() //跳转到登录
		}
  },
  promoCodeTap:function(){
	app.publicnavigateTologing('/pages/PromoCode/PromoCode')
  },
  myCouponTap:function(){
	app.publicnavigateTologing('/pages/coupon/coupon')
  },
  aboutTap:function(e){
	app.publicnavigateTologing('/pages/brief/brief?aid='+e.currentTarget.dataset.aid)
  },
  customerServiceTap:function(){
	app.publicnavigateTologing('/pages/customerService/customerService')
  },
  logoutTap:function(){
	  //退出登录状态
	  app.logout()
    wx.redirectTo({
      url: '/pages/login/login'
    })
  }
})